package com.em.sugarfight.entity;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 路径类 - 存储完整路径信息
 */
@Data
public class Path {
    private List<Position> waypoints;
    private double totalCost;

    public Path() {
        this.waypoints = new ArrayList<>();
        this.totalCost = 0.0;
    }

    public Path(List<Position> waypoints, double totalCost) {
        this.waypoints = new ArrayList<>(waypoints);
        this.totalCost = totalCost;
    }

    /**
     * 从PathNode重建路径
     */
    public static Path reconstructFrom(PathNode endNode) {
        List<Position> path = new ArrayList<>();
        PathNode current = endNode;

        while (current != null) {
            path.add(0, current.getPosition()); // 逆序添加
            current = current.getParent();
        }

        return new Path(path, endNode.getCost());
    }

    public Position getNextStep() {
        if (waypoints.size() <= 1) return null;
        return waypoints.get(1); // 返回下一步位置
    }

    public boolean isEmpty() {
        return waypoints.isEmpty();
    }

    public int getLength() {
        return waypoints.size();
    }

    public List<Position> getWaypoints() {
        return new ArrayList<>(waypoints);
    }

    public double getTotalCost() {
        return totalCost;
    }
}